#!/usr/bin/python
# -*- coding: utf-8 -*-

# library for ldap protocol tools
import ldap
import ldap.ldapobject as ldapo

# Ldap object based on ReconnectLDAPObject which ensure stable ldap connection (version 3)
class OmenReconnectLdapObject(ldapo.ReconnectLDAPObject):
    def __init__(self, host, port, ssl, ca_cert):
        protocol = 'ldaps' if ssl else 'ldap'
        ldapo.ReconnectLDAPObject.__init__(self, "%s://%s:%d" % (protocol, host, port), retry_max=2, retry_delay=1)
        self.protocol_version = ldap.VERSION3
        if ssl:
            ldap.set_option(ldap.OPT_X_TLS_CACERTFILE, ca_cert)
            
    def connect(self, user, password):
        self.simple_bind_s(user, password)
        
        